package data.set.adaptator;

import java.util.Iterator;

import algorithm.Classifier;

import tools.Pair;

import data.set.OfflineSet;
import data.set.OfflineSetIterator;


/**
 * This class describes a set build with a label from a classifier
 * @author denoyer
 *
 */
public class SupervisedOfflineSet_To_PairOfflineSetUsingClassifier<X,Y> implements OfflineSet<Pair<Y,Y>>
{
	private Classifier<X,Y> machine;
	private OfflineSet<Pair<X,Y>> set;
	
	public SupervisedOfflineSet_To_PairOfflineSetUsingClassifier(Classifier<X,Y> machine,OfflineSet<Pair<X,Y>> set)
	{
		this.machine=machine;
		this.set=set;
	}
	
	
	public Pair<Y, Y> getObject(int id) 
	{
		X x=set.getObject(id).getX();
		Y y=machine.map(x);
		return(new Pair<Y,Y>(y,set.getObject(id).getY()));
	}

	
	public OfflineSetIterator<Pair<Y, Y>> inputsetiterator() {
		OfflineSetIterator<Pair<Y, Y>> it=new IT(set.inputsetiterator());
		return(it);
	}

	
	public long size() 
	{
		return(set.size());
	}

	
	public Iterator<Pair<Y, Y>> iterator() {
		return(new Iterator_FromOfflineSetIterator<Pair<Y,Y>>(inputsetiterator()));
	}

	private class IT implements OfflineSetIterator<Pair<Y,Y>>
	{
		private OfflineSetIterator<Pair<X,Y>> it;
		
		public IT(OfflineSetIterator<Pair<X,Y>> it)
		{
			this.it=it;
		}

		
		public int getCurrentId() {
			return it.getCurrentId();
		} 

		
		public Pair<Y, Y> getCurrentObject() {
			Pair<X,Y> p=it.getCurrentObject();
			Y y=machine.map(p.getX());

			return new Pair<Y,Y>(y,p.getY());
		}

		
		public boolean hasNext() {
			return it.hasNext();
		}

		
		public void next() {
			it.next();
		}
	}
}
